package com.chtw.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chtw.entity.Allmessage;
import com.chtw.service.AllMessageService;
import com.chtw.utils.Result;

@Controller
@RequestMapping("/message")
public class AllMessageController {

	@Autowired
	private AllMessageService allService;
	
	/**
	 * 添加消息
	 * @param allmessage
	 * @return
	 */
	@RequestMapping("/addMessage")
	@ResponseBody
	public Result addMessage(Allmessage allmessage,HttpSession session) {
		int i = allService.addMessage(allmessage,session);
		if(i>0) {
			return Result.seccess();
		}else {
			return Result.fail("发布消息失败！");
		}
	}
	
	/**
	 * 管理员获取待审核消息
	 * @return
	 */
	@RequestMapping("/getExamine")
	@ResponseBody
	public Result getExamine() {
		List<Allmessage> aList = allService.getExamine();
		if(aList.size()>0||aList.size()==0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 管理员删除消息
	 * @param mid
	 * @return
	 */
	@RequestMapping("/deleMessage")
	@ResponseBody
	public Result deleMessage(int mid) {
		int i = allService.deleMessage(mid);
		if(i>0) {
			return Result.seccess();
		}else {
			return Result.fail("删除失败！");
		}
	}
	
	/**
	 * 审核操作(通过或不通过)
	 * @param mid
	 * @return
	 */
	@RequestMapping("/Pass")
	@ResponseBody
	public Result noPass(int mid,int no) {
		int i = allService.Pass(mid,no);
		if(i>0) {
			return Result.seccess();
		}else {
			return Result.fail("审核不通过失败！");
		}
	}
	
	/**
	 * 获取审核通过的消息
	 * @return
	 */
	@RequestMapping("/getpass")
	@ResponseBody
	public Result getpass() {
		List<Allmessage> aList = allService.getpass();
		if(aList.size()>0||aList.size()==0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 获取审核未通过的消息
	 * @return
	 */
	@RequestMapping("/getNopass")
	@ResponseBody
	public Result getNopass() {
		List<Allmessage> aList = allService.getNopass();
		if(aList.size()>0||aList.size()==0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 忽略掉的审核
	 * @return
	 */
	@RequestMapping("/gethulue")
	@ResponseBody
	public Result gethulue() {
		List<Allmessage> aList = allService.gethulue();
		if(aList.size()>0||aList.size()==0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 批量处理
	 * @return
	 */
	@RequestMapping("/allfunc")
	@ResponseBody
	public Result allfunc(String str) {
		int i = allService.allfunc(str);
		if(i>0) {
			return Result.seccess();
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 教师获取自己发布的消息
	 * @return
	 */
	@RequestMapping("/getmeadd")
	@ResponseBody
	public Result getmeadd(HttpSession session) {
		List<Allmessage> aList = allService.getmeadd(session);
		if(aList.size()>=0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
	
	/**
	 * 学生获取低级审核通过的消息
	 * @return
	 */
	@RequestMapping("/getme")
	@ResponseBody
	public Result germe() {
		List<Allmessage> aList = allService.getme();
		if(aList.size()>=0) {
			return Result.seccess(aList);
		}else {
			return Result.fail("获取失败！");
		}
	}
}
